from pydantic import BaseModel
from typing import Optional
from datetime import datetime, timedelta

class DahuaConfig(BaseModel):
    """大华平台配置"""
    # 基础配置
    api_host: str = "http://10.35.70.49"  # 本地模拟服务器地址
    app_key: str
    client_id: str = 'root'
    client_secret:str = '32a85a8f-0dd9-4cec-a8df-8dee2b836007'
    username:str = 'systen'
    password:str = 'jinyu123'
    
    # 认证相关
    auth_path: str = "/oauth/extend/token"  # 认证接口路径
    public_key: str = "/evo-apigw/evo-oauth/1.0.0/oauth/public-key"  # 认证接口路径
    
    # 事件订阅相关
    event_host: str = "http://localhost:8002"  # 本地模拟服务器地址
    event_subscribe_path: str = "/dahua/eventbus/subscribe"  # 订阅接口路径
    event_unsubscribe_path: str = "/dahua/eventbus/unsubscribe"  # 取消订阅接口路径
    
    # 回调相关配置
    callback_path: str = "/api/callbacks/dahua"  # 回调路径
    callback_host: str  # 本机地址
    callback_port: int = 8003  # 回调服务器端口

class HikvisionConfig(BaseModel):
    """海康平台配置"""
    # 基础配置
    api_host: str = "http://localhost:8002"  # 本地模拟服务器地址
    app_key: str
    app_secret: str
    access_token: Optional[str] = None
    token_expires_at: Optional[datetime] = None
    
    # 认证相关
    auth_path: str = "/hikvision/oauth/token"  # 认证接口路径
    
    # 事件订阅相关
    event_host: str = "http://localhost:8002"  # 本地模拟服务器地址
    event_subscribe_path: str = "/hikvision/api/v1/events/subscribe"  # 订阅接口路径
    event_unsubscribe_path: str = "/hikvision/api/v1/events/unsubscribe"  # 取消订阅接口路径
    
    # 回调相关配置
    callback_path: str = "/api/callbacks/hikvision"  # 回调路径
    callback_host: str  # 本机地址
    callback_port: int = 8003  # 回调服务器端口

class PlatformConfig:
    """平台配置管理"""
    def __init__(self):
        self.dahua = DahuaConfig(
            app_key="mock_app_key",  # 模拟的key
            app_secret="mock_app_secret",  # 模拟的secret
            callback_host="localhost"  # 本地测试地址
        )
        
        self.hikvision = HikvisionConfig(
            app_key="mock_app_key",  # 模拟的key
            app_secret="mock_app_secret",  # 模拟的secret
            callback_host="localhost"  # 本地测试地址
        )
    
    def get_dahua_callback_url(self) -> str:
        """获取大华平台回调URL"""
        return f"http://{self.dahua.callback_host}:{self.dahua.callback_port}{self.dahua.callback_path}"
    
    def get_hikvision_callback_url(self) -> str:
        """获取海康平台回调URL"""
        return f"http://{self.hikvision.callback_host}:{self.hikvision.callback_port}{self.hikvision.callback_path}"

# 创建全局配置实例
platform_config = PlatformConfig() 